/**
 *
 */
package com.ssh.ser.comonstaff;

import com.ssh.dao.StaffDAOI;
import com.ssh.entity.Staff;
import com.ssh.model.Constant;

/**
 * @author jack
 *
 */
public class UpdatePasswdServiceImpl implements IUpdatePasswdService {

	StaffDAOI staffDAOI;

	public UpdatePasswdServiceImpl() {
		super();
	}

	/**
	 * @return the staffDAOI
	 */
	public StaffDAOI getStaffDAOI() {
		return staffDAOI;
	}

	/**
	 * @param staffDAOI the staffDAOI to set
	 */
	public void setStaffDAOI(StaffDAOI staffDAOI) {
		this.staffDAOI = staffDAOI;
	}

	@Override
	public int updatePasswd(String staffId, String newPasswd, String oldPasswd) {
		// TODO Auto-generated method stub
		Staff staff = staffDAOI.queryStaffByStaffId(staffId);
		if (!staff.getPassword().equals(oldPasswd))
			return Constant.NORMAL;
		staff.setPassword(newPasswd);
		if (staffDAOI.updateStaff(staff) != null)
			return Constant.OK;
		return Constant.FAIL;
	}

}
